from openpyxl import Workbook
# 导入Font类，用于设置单元格字体
from openpyxl.styles import Font
# 导入Alignment类，用于设置单元格对齐方式
from openpyxl.styles import Alignment

wb = Workbook()
ws = wb.active

ws['A1'] = 'A得分'
ws['B1'] = 'B得分'

ws.merge_cells('C1:F1')
# 合并G1到J1单元格，作为B方球员详细信息的分组标题
ws.merge_cells('G1:J1')
# 在合并后的单元格中写入分组标题
ws['C1'] = 'A'
ws['G1'] = 'B'

ws['K1'] = '得分方'     # 记录该回合的得分方
ws['L1'] = '回合数'     # 记录回合编号
ws['M1'] = '非受迫失误' # 记录非受迫性失误
ws['N1'] = '受迫失误'   # 记录受迫性失误
ws['O1'] = '制胜分'     # 记录制胜分

ws['C2'] = '球员位置'    # 记录球员击球时的位置
ws['D2'] = '动作'        # 记录击球动作类型
ws['E2'] = '击球落点'    # 记录球的落点位置
ws['F2'] = '球速'        # 记录击球速度

ws['G2'] = '球员位置'
ws['H2'] = '动作'
ws['I2'] = '击球落点'
ws['J2'] = '球速'

ws.merge_cells('A1:A2')
ws.merge_cells('B1:B2')

ws.merge_cells('K1:K2')
ws.merge_cells('L1:L2')
ws.merge_cells('M1:M2')
ws.merge_cells('N1:N2')
ws.merge_cells('O1:O2')

# 设置所有单元格的对齐方式
for row in ws:
    for cell in row:
        cell.alignment = Alignment(horizontal='center', vertical='center', wrapText=True)

wb.save('example.xlsx')
